home *** CD-ROM | disk | FTP | other *** search
/ Adobe Graphics & Publishing SDK 1996 December / Adobe Graphics & Publishing SDK 1996 December.iso / pc / ps40sdk / examples / selection / shape / common / shape.c next >
Encoding:
C/C++ Source or Header  |  1996-09-17  |  2.8 KB  |  147 lines

  1. /*
  2.    File: Shape.c
  3.  
  4.    Copyright (c) 1996, Adobe Systems Incorporated.
  5.    All rights reserved.
  6.    
  7. */
  8.  
  9. #if __MWERKS__
  10. #include <SetupA4.h> // A4-globals
  11. #include <A4Stuff.h> // A4-globals
  12. #endif
  13.  
  14. #if defined(THINK_C) || defined(__MWERKS__)
  15. #define ENTRYPOINT main
  16. #endif
  17.  
  18. #include "Shape.h"
  19.  
  20. Handle hDllInstance = NULL;
  21.  
  22. /*****************************************************************************/
  23.  
  24. void InitGlobals (GPtr globals);
  25. void DoExecute (GPtr globals);
  26.  
  27. /*****************************************************************************/
  28.  
  29. /* All calls to the plug-in module come through this routine. It must be
  30.    placed first in the resource. To achieve this, most development systems
  31.    require that this be the first routine in the source. */
  32.  
  33. #if MSWindows
  34. void ENTRYPOINT (short selector,
  35.                         PISelectionParams *selectionParamBlock,
  36.                         long *data,
  37.                         short *result)                
  38. #else
  39. pascal void ENTRYPOINT (short selector,
  40.                         PISelectionParams *selectionParamBlock,
  41.                         long *data,
  42.                         short *result)                
  43. #endif
  44.     {
  45.     
  46.     Globals globalValues;
  47.     GPtr globals = &globalValues;
  48.     
  49.     #if __MWERKS__
  50.     EnterCodeResource(); // A4-globals
  51.     #endif
  52.     
  53.     if (!*data)
  54.         {
  55.         
  56.         InitGlobals (globals);
  57.  
  58.         *data = (long) NewHandle (sizeof (Globals));
  59.         
  60.         if (!*data)
  61.             {
  62.             *result = memFullErr;
  63.             return;
  64.             }
  65.             
  66.         ** (GHdl) *data = globalValues;
  67.         
  68.         }
  69.         
  70.     globalValues = ** (GHdl) *data;
  71.         
  72.     gStuff = selectionParamBlock;
  73.     gResult = noErr;
  74.    
  75.     switch (selector)
  76.     {
  77.         
  78.         case selectionSelectorAbout:
  79.             DoAbout (globals);
  80.             break;
  81.             
  82.         case selectionSelectorExecute:
  83.             DoExecute (globals);
  84.             break;
  85.             
  86.         default:
  87.             gResult = selectionBadParameters;
  88.     }
  89.         
  90.     *result = gResult;
  91.     ** (GHdl) *data = globalValues;
  92.  
  93.     #if __MWERKS__
  94.     ExitCodeResource(); // A4-globals
  95.     #endif
  96. }
  97.  
  98. /*****************************************************************************/
  99.  
  100. void InitGlobals (GPtr globals)
  101. {    
  102.     gWhatShape = iShapeTriangle;
  103.     gCreate = iCreateSelection;
  104.     gQueryForParameters = true;
  105. }    
  106.  
  107. /*****************************************************************************/
  108.  
  109. void DoExecute (GPtr globals)
  110. {
  111.     Boolean            doThis = true;
  112.     int32            size = 0; // DWORD int32 size;
  113.     Ptr                p = NULL; // LPVOID Ptr hPtr;
  114.  
  115.     gQueryForParameters = ReadScriptParams (globals);
  116.  
  117.     if ( gQueryForParameters ) doThis = DoParameters (globals);
  118.  
  119.     if ( doThis )
  120.     {
  121.         p = PIGetResource (PathResource, (int32)(ResourceID+gWhatShape), &size);
  122.         if (p == NULL || size < 1)
  123.             {
  124.             gResult = -1;
  125.             return;
  126.             }
  127.             
  128.         gStuff->newPath = PINewHandle (size);
  129.         
  130.         if (gStuff->newPath == NULL)
  131.             {
  132.             gResult = memFullErr;
  133.             return;
  134.             }
  135.  
  136.         memcpy(*gStuff->newPath, p, size);
  137.         PIReleaseResource(p);
  138.  
  139.         /* look in gStuff->supportedTreatments for support for this next thang */
  140.         
  141.         gStuff->treatment = KeyToEnum(EnumToKey(gCreate,typeCreate),typePISel);
  142.  
  143.         WriteScriptParams (globals);
  144.     } // user cancelled or dialog err or silent
  145. }
  146.  
  147.